package com.kws.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.kws.common.core.domain.R;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.system.domain.info.QueryDepartureAddressInfo;
import com.kws.system.domain.vo.CreateDepartureAddressRq;
import com.kws.system.domain.vo.UpdateDepartureAddressRq;
import com.kws.system.service.SysDepartureAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <b>SysDepartureAddressController</b>
 *
 * @description: SysDepartureAddressController <br>
 * @date: 2024/11/6 18:37 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "发货地址管理模块")
@RestController
public class SysDepartureAddressController {
    private static final Logger logger = LoggerFactory.getLogger(SysDepartureAddressController.class);

    @Autowired
    private SysDepartureAddressService sysDepartureAddressService;

    @ApiOperation("分页查询发货地址列表")
    @GetMapping("/query/departureAddress/page")
    public R<Page<QueryDepartureAddressInfo>> queryDepartureAddressPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                        @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                        @RequestParam(required = false) String consignerName){
        Page<QueryDepartureAddressInfo> pageInfo = sysDepartureAddressService.queryDepartureAddressPage(pageNum,pageSize,consignerName);
        return R.ok(pageInfo);
    }

    @ApiOperation("新增发货地址信息")
    @PostMapping("/create/departureAddress")
    public R createDepartureAddress(@RequestBody CreateDepartureAddressRq rq){
        boolean status = sysDepartureAddressService.createDepartureAddress(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID查询发货地址详情")
    @GetMapping("/query/departureAddress/byId")
    public R<QueryDepartureAddressInfo> queryDepartureAddressById(@RequestParam Long id){
        QueryDepartureAddressInfo info = sysDepartureAddressService.queryDepartureAddressById(id);
        return R.ok(info);
    }

    @ApiOperation("修改发货地址")
    @Log(title = "修改发货地址", businessType = BusinessType.UPDATE)
    @PostMapping("/update/departureAddress")
    public R updateDepartureAddress(@RequestBody UpdateDepartureAddressRq rq){
        boolean status = sysDepartureAddressService.updateDepartureAddress(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID删除发货地址")
    @Log(title = "删除发货地址", businessType = BusinessType.DELETE)
    @GetMapping("/delete/departureAddress/byId")
    public R deleteDepartureAddressById(@RequestParam Long id){
        boolean status = sysDepartureAddressService.deleteDepartureAddressById(id);
        return R.ok(status);
    }
}
